package com.example.demo;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Header {
    @RequestMapping("/getUser-Agent")
    public String test1User(HttpServletRequest httpServletRequest){
        String header = httpServletRequest.getHeader("User-Agent");
        return header;
    }
    @ResponseBody
    @RequestMapping("/getUser-Agent2")
    //RequestHeader调用信息所以需要使用@ResponseBody
    public String test2User(@RequestHeader("User-Agent") String header){
        return header;
    }
    @RequestMapping("/getHost")
    public String testHost(HttpServletRequest httpServletRequest){
        String host = httpServletRequest.getHeader("Host");
        return host+"\"od\"";
    }
}
